package xin.marcher.module.quality.api.impl;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import xin.marcher.module.common.core.JsonResult;
import xin.marcher.module.common.core.PageResult;
import xin.marcher.module.common.exception.ProductBizException;
import xin.marcher.module.quality.api.ItemQualityControlSurveyTaskApi;
import xin.marcher.module.quality.domain.dto.ItemQualityControlSurveyTaskToSellerDTO;
import xin.marcher.module.quality.domain.request.SurveyFormRequest;
import xin.marcher.module.quality.service.ItemQualityControlSurveyTaskService;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 */
@Slf4j
public class ItemQualityControlSurveyTaskApiImpl implements ItemQualityControlSurveyTaskApi {

    @Resource
    private ItemQualityControlSurveyTaskService surveyTaskService;

    /**
     * 卖家查询调查单详情
     *
     * @param request
     * @return
     */
    @Override
    public JsonResult<List<ItemQualityControlSurveyTaskToSellerDTO>> surveyFormList(SurveyFormRequest request) {
        try {
            PageResult pageResult = surveyTaskService.surveyFormList(request);
            return JsonResult.buildSuccess(pageResult.getContent());
        } catch (ProductBizException e) {
            log.error("biz error: request={}", JSON.toJSONString(request), e);
            return JsonResult.buildError(e.getErrorCode(), e.getErrorMsg());
        } catch (Exception e) {
            log.error("system error: request={}", JSON.toJSONString(request), e);
            return JsonResult.buildError(e.getMessage());
        }
    }
}
